package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@Api(tags = "护理计划管理")
@RequestMapping("/nursing/plan")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 护理计划分页查询
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("护理计划分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getList(@RequestParam(required = false) String name,
                                                               @RequestParam(required = false) Integer status,
                                                               @RequestParam Integer pageNum,
                                                               @RequestParam Integer pageSize){
            log.info("护理计划分页查询，入参planName={},status={},pageNum={},pageSize={}",name,status,pageNum,pageSize);
            PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getList(name,status,pageNum,pageSize);
            return ResponseResult.success(pageResponse);
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
            log.info("新增护理计划接口，入参={}",nursingPlanDto);
            nursingPlanService.addNursingPlan(nursingPlanDto);
            return ResponseResult.success();
    }

    /**
     * 查询护理计划信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        log.info("查询护理计划信息,入参id={}",id);
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 更新护理计划信息
     * @param planDto
     * @return
     */
    @PutMapping("/{id}")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto planDto){
        log.info("更新护理计划接口，入参={}",planDto);
        nursingPlanService.updateNursingPlan(planDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id){
        log.info("删除护理计划接口,入参id={}",id);
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    /**
     * 更新启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status){
        log.info("更新启用禁用接口，入参id={},status={}",id,status);
        nursingPlanService.updateStatus(id,status);
        return ResponseResult.success();
    }

    /**
     * 查询所有护理计划
     * @return
     */
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAllPlan(){
        log.info("查询所有护理计划接口");
        List<NursingPlanVo> planVos = nursingPlanService.getAllPlan();
        return ResponseResult.success(planVos);
    }
}
